package com.lza.response;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*公共返回类
 */
@Data
public class Result {
    //是否成功
    private boolean success;
    //返回码
    private Integer code;
    //返回信息
    private String message;
    //返回数据
    private Map<String,Object> data=new HashMap<>();



    private Result(){
        /*构造放回私有化，里面的方法都是静态的，
    达到保护属性的作用
     */
    }

    /**使用链式编程*/
    public static Result ok(){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
       return result;
    }
    /**使用链式编程*/
    public static Result error(){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR.getCode());
        result.setMessage(ResultCode.ERROR.getMessage());
        return result;
    }
    /*自定义返回成功也否,也是链式编程

     */
    public Result getData(Map<String,Object> map){
        this.setData(map);
        return this;
    }
    public Result getData(String key, Object value){
        this.data.put(key, value);
        return this;
    }
    public Result getCode(Integer code){
        this.setCode(code);
        return this;
    }
    public Result getMessage(String message){
        this.setMessage(message);
        return this;
    }



}
